package yt.kpool.view;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.util.ArrayList;
import java.util.List;

import yt.kpool.R;
import yt.kpool.bean.LineChartTestBean;

public class MyMarkerDView extends MarkerView {

    private TextView tv_y,tv_y2;
    private TextView tv_x;

    private List<String> timeList;
    private List<LineChartTestBean> listt;
    private String stru;
    public MyMarkerDView(Context context, int layoutResource, String  unit,String stru) {
        super(context, layoutResource);

        this.stru=stru;
        tv_y = (TextView) findViewById(R.id.tv_y);
        tv_x = (TextView) findViewById(R.id.tv_x);
        tv_y2 = (TextView) findViewById(R.id.tv_y2);

        ((TextView) findViewById(R.id.tv_unit)).setText(unit);

        timeList = new ArrayList<>();
    }

    /**
     * 是指横轴日期数据
     */
    public void setTimeList(List<String> list,List<LineChartTestBean> listtt) {
        timeList = list;
        listt=listtt;
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        if (e instanceof CandleEntry) {

            CandleEntry ce = (CandleEntry) e;
            tv_y.setText("" + listt.get((int)e.getData()).getFilingNumber());
            tv_y2.setText(stru+listt.get((int)e.getData()).getTNumber());
            if (timeList.size() > (int) e.getX())
                tv_x.setText("" + timeList.get((int) e.getX()));
        } else {

            tv_y.setText("" + listt.get((int)e.getData()).getFilingNumber());
            tv_y2.setText(stru+listt.get((int)e.getData()).getTNumber());
            if (timeList.size() > (int) e.getX())
                tv_x.setText("" + timeList.get((int) e.getX()));
        }

        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
